package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.IView.IEngineeringUsersListView;
import com.cloudsigns.factorymanager2.engineering.bean.UserInfoBean;
import com.cloudsigns.factorymanager2.engineering.model.EngineeringUsersListModel;
import com.cloudsigns.factorymanager2.engineering.model.IEngineeringUsersListModel;

import java.util.List;

/**
 * Created by tony on 2018/3/28.
 */

public class EngineeringUserListPresenter {
    private IEngineeringUsersListView view;
    private IEngineeringUsersListModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public EngineeringUserListPresenter(IEngineeringUsersListView view) {
        this.view = view;
        this.model = new EngineeringUsersListModel();
    }

    public void getUserList(CommonEnum.ROLECATEGORY rolecategory) {


        model.getUserList(rolecategory, new EngineeringUsersListModel.OnEngineeringUserListListener() {
            @Override
            public void successed(final List<UserInfoBean> userInfoBeanList) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getDataSuccessed(userInfoBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
